package setup

import (
	"tone-agent/core"
	"tone-agent/entity"

	"github.com/spf13/viper"
)

func InitCron() {
	go core.Cron(core.SendHeartbeat, entity.DefaultHeartbeatInterval)
	go core.Cron(core.CheckTaskProcess, entity.DefaultCheckTaskProcessInterval)

	if viper.GetString("mode") == "active" {
		go core.Cron(core.PullTasks, entity.DefaultPullTaskInterval)
		go core.Cron(core.SyncResults, entity.DefaultSyncResultInterval)
	}

	//c := cron.New(cron.WithSeconds())
	//c.AddFunc(GetConfigFromViperWithDefault(
	//	entity.HeartbeatIntervalKey,
	//	entity.DefaultHeartbeatInterval), heartbeat,
	//)
	//c.AddFunc(GetConfigFromViperWithDefault(
	//	entity.CheckProcessIntervalKey,
	//	entity.DefaultCheckTaskProcessInterval), CheckTaskProcess,
	//)
	//if viper.Get("mode") == "active" {
	//	c.AddFunc(GetConfigFromViperWithDefault(
	//		entity.PullTaskIntervalKey,
	//		entity.DefaultPullTaskInterval), pullTasks,
	//	)
	//	c.AddFunc(GetConfigFromViperWithDefault(
	//		entity.SyncResultIntervalKey,
	//		entity.DefaultSyncResultInterval), syncResults,
	//	)
	//}
	//c.Start()
}
